package com.mojo.linearlist;

import java.util.StringJoiner;

/**
 * 数据结构，线性表-链表
 *
 * @author <a href="mailto:sjj@jianzhimao.com">mojo</a>
 * copyright (C), 2013-2022, 广州九尾信息科技有限公司
 * @date 2022/8/25 17:06
 */
public class InitLinked {
    //数据域
    private Object data;
    private InitLinked head;
    private InitLinked next;

    public InitLinked() {
    }

    public InitLinked(Object data, InitLinked next) {
        this.data = data;
        this.next = next;
    }

    @Override
    public String toString() {
        return new StringJoiner(", ", InitLinked.class.getSimpleName() + "[", "]")
                .add("data=" + data)
                .add("head=" + head)
                .add("next=" + next)
                .toString();
    }

    /**
     * 链表删除
     *
     * @param index 索引
     * @return void
     */
    public void delete(int index) {

    }

    public boolean add(int val) {
        final InitLinked l;
        InitLinked newNode = new InitLinked(val, null);
        l = newNode;
        if (newNode != null) {
            next = l;
        }
        return true;
    }
    public static void main(String[] args) {
        initLinked();
    }

    private static void initLinked() {
        InitLinked link = new InitLinked(0, new InitLinked());
        for (int i = 1; i < 5; i++) {
            link.add(i);

        }
        System.out.println(link);
    }
}
